//
//  NativeThirdLoginShareChannel.m
//  kq_flutter_core_widget
//
//  Created by wtb on 2024/12/27.
//

#import "NativeThirdLoginShareChannel.h"
#import "WxChannelApi.h"
#import "DtChannelApi.h"
#import "QqChannelApi.h"

@implementation NativeThirdLoginShareChannel

+(void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar{
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"flutter.keqiang.com/thirdLogin" binaryMessenger:[registrar messenger]];
    NativeThirdLoginShareChannel *lSchannel = [[NativeThirdLoginShareChannel alloc] init];
    [registrar addApplicationDelegate:lSchannel];
    [registrar addMethodCallDelegate:lSchannel channel:channel];
}

-(void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result{
    // if ([@"isInitialWxApp" isEqualToString:call.method]){
    //     // 是否安装了微信app
    //     [[WxChannelApi defualtWxChannelApi] isInitialWxApp:result];
    // }else if ([@"registerWx" isEqualToString:call.method]){
    //     // 注册weixin
    //     [[WxChannelApi defualtWxChannelApi] registerWx:call result:result];
    // }else if ([@"registerDT" isEqualToString:call.method]){
    //        // 注册weixin
    //        [DtChannelApi registerDt:call result:result];
    //    }else if ([@"isInitialDTApp" isEqualToString:call.method]){
    //        // 是否安装了钉钉app
    //        [DtChannelApi isInitialDtApp:result];
    //    }else if([@"ddAuth" isEqualToString:call.method]){
    // 钉钉登录
    //   }else if([@"isInitialQQApp" isEqualToString:call.method]){
    // 是否安装qq
    //  }
    if ([@"wxAuth" isEqualToString:call.method]) {
        // 微信登录
        [[WxChannelApi defualtWxChannelApi] handleWxAuthCall:call result:result];
    }else if([@"shareWxTextData" isEqualToString:call.method]){
        // 微信文本分享
        [[WxChannelApi defualtWxChannelApi] handleWxShareTextCall:call result:result];
        
    }else if([@"shareWxWebData" isEqualToString:call.method]){
        // 微信网页分享
        [[WxChannelApi defualtWxChannelApi] handleWxShareWebCall:call result:result];
        
    }else if([@"shareWxImageData" isEqualToString:call.method]){
        // 微信图片分享
        [[WxChannelApi defualtWxChannelApi] handleWxShareImageCall:call result:result];
        
    }else if([@"openMiniProgram" isEqualToString:call.method]){
        // 打开微信小程序
        [[WxChannelApi defualtWxChannelApi] openMiniProgramCall:call result:result];
    }else if([@"qqAuth" isEqualToString:call.method]){
        // qq登录
        [[QqChannelApi defualtQqChannelApi] handleQqAuthCall:call result:result];
    }else if([@"shareQQTextData" isEqualToString:call.method]){
        // QQ文本分享
        [[QqChannelApi defualtQqChannelApi] handleQqShareTextCall:call result:result];
        
    }else if([@"shareQQWebData" isEqualToString:call.method]){
        // QQ网页分享
        [[QqChannelApi defualtQqChannelApi] handleQqShareWebCall:call result:result];
        
    }else if([@"shareQQImageData" isEqualToString:call.method]){
        // QQ图片分享
        [[QqChannelApi defualtQqChannelApi] handleQqShareImageCall:call result:result];
        
    } else if([@"shareDDTextData" isEqualToString:call.method]){
        // 钉钉文本分享
        [[DtChannelApi defualtDtChannelApi] handleDTShareTextCall:call result:result];
        
    }else if([@"shareDDWebData" isEqualToString:call.method]){
        // 钉钉网页分享
        [[DtChannelApi defualtDtChannelApi] handleDTShareWebCall:call result:result];
        
    }else if([@"shareDDImageData" isEqualToString:call.method]){
        // 钉钉图片分享
        [[DtChannelApi defualtDtChannelApi] handleDTShareImageCall:call result:result];
    }
}

#pragma mark - AppDelegate

- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url{
    
    return [WxChannelApi handleWXOpenURL:url] || [QqChannelApi handleOpenURL:url] || [DtChannelApi handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application
              openURL:(NSURL *)url
    sourceApplication:(NSString *)sourceApplication
           annotation:(id)annotation {
    return [WxChannelApi handleWXOpenURL:url] || [QqChannelApi handleOpenURL:url] || [DtChannelApi handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:
                (NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
    return [WxChannelApi handleWXOpenURL:url] || [QqChannelApi handleOpenURL:url] || [DtChannelApi handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application
    continueUserActivity:(NSUserActivity *)userActivity
      restorationHandler:(void (^)(NSArray *_Nonnull))restorationHandler {
    return [WxChannelApi handleOpenUniversalLink:userActivity] || [QqChannelApi continueUserActivity:userActivity];
}

@end
